package com.hd.aop0410.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect/*当前类是一个切面类*/
@Component
public class TestAspect {
    @Pointcut("execution(* com.hd.aop0410.controller..*.*(..) )")
    public void mypointcut01() {
    }

    @Before("mypointcut01()")
    public void beforeo()

    {
        System.out.println("====以前====");
    }

    @After("mypointcut01()")
    public void after() {
        System.out.println("-------------");
    }

    /*注意(1)，环能通知需要有返回值
    注意(2)，环绕通知需要接收一个特定类型(ProceedingJoinPoint）的参数zl*/

    @Around("mypointcut01()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
//        System.out.println("环绕 ");
        long start = System.currentTimeMillis();
        Object result = pjp.proceed();//让目标方法继续执行
        long end = System.currentTimeMillis();
        System.out.println("time usesd ->" + (end - start));
        return result;
    }
}
